package Handler;

import dao.IAddressDao;
import dao.ICartEntryDao;
import dao.impl.AddressDaoImpl;
import dao.impl.CartEntryDaoImpl;
import pojo.CartEntry;
import pojo.ShopCart;
import pojo.User;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class OrderHandler {
    public void confOrder(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            User user= (User) request.getSession().getAttribute("user");
            IAddressDao addressDao=new AddressDaoImpl();
            List<String> address=addressDao.findAddressByUserInfoId(user.getUserInfo().getUserinfoid());
            ICartEntryDao cartEntryDao=new CartEntryDaoImpl();
            List<CartEntry> cartEntryList=cartEntryDao.findByShopCartId(user);
            request.setAttribute("cartEntryList",cartEntryList);
            request.setAttribute("addressList",address);
            request.getRequestDispatcher("/order/confOrder.jsp").forward(request, response);
        } catch (Exception e) {
            e.printStackTrace();
            request.getRequestDispatcher("/user/login.jsp").forward(request, response);
        }

    }
}
